<?php
namespace Admin\Controller;
use Think\Controller;
class KissController extends CommonController {
	//等级显示
    public function index()
    {
        $sql = 'select * from kisslev';
        $kisslev = M()->query($sql);
        $this->assign('kisslev',$kisslev);

        $this->display();
    }

    //add页面
    public function add()
    {
    	$this->display();
    }

    //add
    public function add_row()
    {
       //print_r($_POST);exit;
        if (IS_POST) {
            $data['name'] = I('post.name');
            $data['max'] = I('post.level-max');
            $data['min'] = I('post.level-min');

           $res = M('level')->add($data);
           if ($res) {
            $arr = array(
                    'error' =>1,
                    'info'=>"添加成功"
                    );
            echo json_encode($arr);
           }else {
            $arr = array(
                    'error' =>0,
                    'info'=>"添加失败"
                    );
            echo json_encode($arr);
           }
        }
    }

    //edit页面
    public function edit()
    {
        $id = I('get.id');
        $levelinfo = M('level')->where(array('id'=>$id))->select();
        $this->assign('levelinfo',current($levelinfo));

        $this->display();
    } 

    //edit
    public function edit_row()
    {
        //print_r($_POST);exit;
        if (IS_POST) {
            $id = I('post.level-id');
            $data['name'] = I('post.name');
            $data['max'] = I('post.level-max');
            $data['min'] = I('post.level-min');

            $res =  M('level')->where(array('id'=>$id))->save($data);
            if ($res) {
                $arr = array(
                "error" => 1,
                "info" => "栏目修改成功"
                );
            echo json_encode($arr);
            }else {
                $arr = array(
                    "error" => 0,
                    "info" => "栏目修改失败"
                    );
                echo json_encode($arr);
            }
        }
    } 

    //删除
    public function del()
    {
      if (IS_POST) {
          $id = I('post.levelid');
          $sql = 'delete from level where id='.$id;
          $is_del = M()->execute($sql);
          if ($is_del) {
              $arr = array(
                  'error' =>0,
                  'info'=>"级别删除成功"
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' =>1,
                  'info'=>"级别删除失败"
                  );
              echo json_encode($arr);
          }
      }  

    }



}